#include<bits/stdc++.h>
using namespace std;
#define N 200005
int a[N], dp[N];
int main()
{
    int n;
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i)
        scanf("%d", &a[i]);
    for(int i = 1; i <= n; ++i)
        dp[i] = max(a[i], a[i] + dp[i-1]);
    int maxNum = dp[1];
    for(int i = 2; i <= n; ++i)
        maxNum = max(maxNum, dp[i]);
    printf("%d", maxNum);
    return 0;
}
